﻿using System.Globalization;

namespace Homework2_6
{
    /// <summary>
    /// output the calendar of the current month
    /// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            // obtain the current month
            DateTime currentDate = DateTime.Today;
            int year = currentDate.Year;
            int month = currentDate.Month;

            // establish the calendar
            Console.WriteLine($"  {currentDate.ToString("MMMM yyyy")}");

            // output the headline
            Console.WriteLine(" Sun Mon Tue Wed Thu Fri Sat");

            // obtain the first day of this month
            DateTime firstDayOfMonth = new DateTime(year, month, 1);
            int dayOfWeek = (int)firstDayOfMonth.DayOfWeek;

            // get the total day of this month
            int daysInMonth = DateTime.DaysInMonth(year, month);

            //beautify the calendar 
            for (int i = 0; i < dayOfWeek; i++)
            {
                Console.Write("    ");
            }

            // output the calendar
            for (int day = 1; day <= daysInMonth; day++)
            {
                Console.Write($"{day,3} ");

                if ((day + dayOfWeek) % 7 == 0)
                {
                    Console.WriteLine();
                }
            }
        }
    }
}

